﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeTop.复习九月份
{
    public class Solution169
    {
        public int MajorityElement(int[] nums)
        {
            int len = nums.Length;
            int top = -1;
            int num = 0;
            for (int i = 0; i < len; i++)
            {
                if (num == 0)
                {
                    //自动上位
                    top = nums[i];
                    num = 1;
                    continue;
                }

                if (nums[i] != top)
                {
                    num--;
                }
                else
                {
                    num++;
                }
                Console.WriteLine(top);
            }
            return top;
        }
    }

    internal class Program169
    {
        private static void Main169(string[] args)
        {
            Solution169 solution169 = new Solution169();
            int[] nums = [6, 5, 5];
            solution169.MajorityElement(nums);
        }
    }
}